<template>
    <div>
        名称
        <input type="text" name="" id="" v-model="page.name">
        <a :href="'https://localhost:7019/api/Xlsx'">导出</a>
        <input type="button" value="查询" @click="show">
        <table>
            <thead>
                <tr>
                    <td>
                        <input type="checkbox" name="" @change="all" v-model="type"  id="">
                    </td>
                    <td>编号</td>
                    <td>名称</td>
                   
                    <td>状态</td>
                    <td>服务时长</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in list">
                    <td>
                        <input type="checkbox" name="" v-model="ids" :value="a.id"  id="">
                    </td>
                    <td>{{a.code}}</td>
                    <td>{{a.hname }}</td>
                    <td>{{ a.state?"启用":"禁用" }}</td>
                    <td>{{ a.time.substring(0,10) }}</td>
                    <td>
                        <input type="button" value="逻辑删除" @click="del(a.id)">
                        <input type="button" v-if="!a.state" value="批量启用" @click="state">
                        <input type="button" v-else value="批量禁用" @click="state">
                    </td>
                </tr>
            </tbody>
        </table>
<input type="button" value="首页" @click="fan(1)">
<input type="button" value="上一页" @click="fan(2)">
<input type="button" value="下一页" @click="fan(3)">
<input type="button" value="尾页" @click="fan(4)">
当前第{{page.paggenow  }}页/共{{ count.pagecount }}页 每页{{page.pagehang  }}行  共{{count.count  }}条
<select v-model="page.pagehang" @change="h">
<option >2</option>
<option >4</option>
<option >5</option>
</select>

<input type="text" name="" id="" v-model="page.paggenow">
        <input type="button" value="跳转" @click="t">
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router=useRouter()
const type=ref(false)
const ids=ref([0])
const t=()=>{
    if(page.value.paggenow>0&&page.value.paggenow<=count.value.pagecount){
       show()
    }
}
const h=()=>{
    show()
}
const all=()=>{
if(type.value){
    for (let index = 0; index < list.value.length; index++) {
    ids.value.push(list.value[index].id)
        
    }
}else{
    ids.value=[0]
}

}
const state=()=>{
   
    axios.get('https://localhost:7019/api/Hospital/State',{params:{idstring:ids.value.toString()}}).then(res=>{
        if(res.data>0){
alert('成功')
show()
}else{
    alert('失败')
}
        
    })
}
const del=(vid:any)=>{
    if(!confirm('确认删除吗')){
        return
    }
    axios.get('https://localhost:7019/api/Hospital/Del',{params:{id:vid}}).then(res=>{
        if(res.data>0){
alert('成功')
show()
}else{
    alert('失败')
}
        
    })
}
onMounted(()=>{
    show()
})
const show=()=>{
    axios.get('https://localhost:7019/api/Hospital/Show',{params:page.value}).then(res=>{
       list.value=res.data.list
       count.value.count=res.data.count
       count.value.pagecount=Math.ceil(count.value.count/page.value.pagehang)

    })
}
const count=ref({
    count:0,
    pagecount:0
   

})
const page=ref({
    paggenow:1,
    pagehang:2,
   
    name:""

})
const list=ref([{
    "id": 0,
      "code": "",
      "hname": "",
      "isdel": true,
      "state": true,
      "time": ""
}])
const fan=(a:any)=>{
if(a==1){
    page.value.paggenow=1;
    show()
}
if(a==2){
    if(page.value.paggenow>1){
        page.value.paggenow-=1;
        show()
    }
    
}
if(a==3){
    if(page.value.paggenow<count.value.pagecount){
        page.value.paggenow+=1;
        show()
    }
    
}
if(a==4){
 
        page.value.paggenow=count.value.pagecount;
        show()

    
}


}
// const add=()=>{
//     axios.post('').then(res=>{

        
//     })
// }
</script>

<style scoped>

</style>